/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2018-2019.
 * Description: support boot_timestamp
 * Author: dangkai <dongkai11@huawei.com>
 * Create: 2018-10-10
 */

#include <linux/kernel.h>
#ifdef CONFIG_ARM64
#include <asm-generic/div64.h>
#else
#include <asm/div64.h>
#endif
#include <linux/sched/clock.h>
#include <linux/hal/boot_timestamp.h>

#define NS_PER_MS 1000000
static unsigned long long initrd_uncompress_start_time;
static unsigned long long initrd_uncompress_end_time;

void get_initrd_start_time(void)
{
	initrd_uncompress_start_time = sched_clock();
}

void get_initrd_end_time(void)
{
	initrd_uncompress_end_time = sched_clock();
}

static unsigned long long count_uncompress_initrd_time(void)
{
	return (initrd_uncompress_end_time - initrd_uncompress_start_time);
}

void print_boot_timestamp(void)
{
	unsigned long long boot_time;
	unsigned long long cost_time;

	boot_time = sched_clock() - boot_start_time;
	cost_time = count_uncompress_initrd_time();

	do_div(boot_time, NS_PER_MS);
	do_div(cost_time, NS_PER_MS);

	printk(KERN_ALERT "**** Total Boot time: %llu ms, uncompress initrd cost %llu ms ****\n",
			boot_time, cost_time);
}
